<template>
	<view>
		<form>
			<!-- 标题 -->
				<view class="cu-form-group margin-top">
					<view class="title">联系电话:</view>
					<input v-model="phone"  placeholder="电话" type="number"></input>
				</view>
				<!-- end -->
				
				<!-- 内容 -->

					<!-- end -->
					
					<!-- 图片 -->

					<!-- end -->
					
					<!-- 地址选择 -->
						<view class="cu-form-group">
							<view class="title">地址选择</view>
							<picker mode="multiSelector" @change="MultiChange" @columnchange="MultiColumnChange" :value="multiIndex"
							 :range="multiArray">
								<view class="picker">
									{{multiArray[0][multiIndex[0]]}},{{multiArray[1][multiIndex[1]]}},{{multiArray[2][multiIndex[2]]}}
								</view>
							</picker>
						</view>
					<!-- end -->
					
					<!-- 价钱 -->

					<!-- end -->
					
					<!-- 选择分类  -->

					<!-- end -->
					
					<!-- 新旧 -->

					<!-- end -->
					
					<!-- 交易方式 -->

					<!-- end -->
					
					<!-- 确定发布 -->
					<view class="padding flex flex-direction">
					  <button class="cu-btn bg-green margin-tb-sm lg" @tap="changeAddress">修改</button>
					</view>
					<!-- end -->
		</form>
		
		<!-- 模态框 -->

		
	</view>
</template>

<script>
	import allSchool from "../../../common/allSchool.js";
	import getTime from '../../component/getNowFormatDate.js'
	import store from '../../../globalStore/store.json'
	export default {
		data() {
			return {
				phone:"",
				user_data:"",


					multiIndex: [0, 0, 0],//地址选择下标
					    multiArray: [
					      ['北京市', '重庆市', '福建省', '江苏省', '广东省', '辽宁省', '内蒙古', '山西省', '青海省', '四川省', '贵州省', '云南省', '陕西省', '西藏', '宁夏', '新疆', '广西', '海南省', '湖南省', '湖北省', '河南省', '山东省', '江西省', '安徽省', '浙江省', '上海', '黑龙江省', '吉林省', '甘肃省', '天津市', '河北省'],
					      [''],
					      ['']
					    ],//默认选择地址
						region: [],//选择地址

			}
		},
		methods: {
		
			// 选择地址
			  MultiChange(e) {
			      this.multiIndex = e.detail.value
			  },
			    MultiColumnChange(e){
			      var that = this;
			      allSchool.all(e,that);
				 
			    },
			  
			  // end
			
			changeAddress(){
				let p=this.multiIndex[0];
				let c=this.multiIndex[1];
				let s=this.multiIndex[2];
				
				let address=this.multiArray[0][p]+" "+this.multiArray[1][c]+" "+this.multiArray[2][s];
				let msg={
					"user_id":this.user_data.user_id,
					"phone":this.phone,
					"address":address
	
				};
				store.user.phone=this.phone
				store.user.address=address
				uni.showLoading();
				
				setTimeout(function () {
					uni.hideLoading();
				}, 2000);
				uniCloud.callFunction({
					name:"setAddress",
					data:msg,
					success(res){
						console.log(res);
						uni.navigateBack();
					}
				})

			},

		},
		onLoad() {
			this.user_data=store.user;
			this.phone=this.user_data.phone;
			let address=this.user_data.address
			let arr=address.split(" ");
			//this.region=arr;
			let province=arr[0];
			let city=arr[1];
			let school=arr[2];
			let index=this.multiArray[0].indexOf(province);
			this.multiArray[1]=[city];
			this.multiArray[2]=[school];
			this.multiIndex=[index,0,0];
		},
		onShow() {
			
		},
		onHide() {
			
		},
		// 出发下拉刷新
		onPullDownRefresh() {
			// 模拟刷新完成
			setTimeout(function(){
				uni.stopPullDownRefresh();
			},2000);
		}
	}
</script>

<style>
.rule{
  display: flex;
  justify-content: space-between;
}
.margin-top-xl-170{
  margin-top: 170rpx;
}
</style>
